home *** CD-ROM | disk | FTP | other *** search
- Path: unixg.ubc.ca!news
- From: jamesdf@unixg.ubc.ca (James Fairweather)
- Newsgroups: comp.lang.c
- Subject: Re: Can anyone HELP with variable delaration? Please?
- Date: Wed, 03 Apr 1996 05:57:05 GMT
- Organization: University of British Columbia
- Message-ID: <3162119a.43634755@news.ucs.ubc.ca>
- References: <4jt07b$dul@news.us.net>
- NNTP-Posting-Host: srtb0411a01.resnet.ubc.ca
- X-Newsreader: Forte Agent .99d/32.182
-
- >I've just started learning C programming (moving up from Pascal) and I can't
- >seem to find an answer to this question. I'm sure this is going to sound
- >stupid, but how can I declare a variable to be of a data type string? Is
- >there a data type "string"?
-
- No there isn't. Instead, we use arrays of characters to make a
- string.
-
- So you can write
-
- char s[] = "Hello, World!";
- or
- char s[20];
- strcpy(s, "Hi yourself.");
-
- Also, any C++ development suite will have a String class, which will
- provide some functionality similar to Pascal's strings.
-
- Here's a little hint about C, though: avoid strings like Ebola! Only
- use strings when it's really necessary to use strings; otherwise use
- constants or integers.
- ---
- James Fairweather
- 4th year Comp. Eng, UBC
- Vancouver, BC, Canada
- jamesdf@unixg.ubc.ca
- 604.228.2269
-